import { query } from '../services/order';

export default {
  namespace: 'orderlist',

  state: {
    orderlists: [],
  },

  effects: {
    //   获取订单
    *fetch(_, { call, put }) {
      const response = yield call(query);
      console.log('test')
      console.log(response)
      console.log('test')
      yield put({
        type: 'save',
        payload: response,
      });
    },
    // *remove({ payload: objs }, { call, put }) {
    //   for (let obj of objs) {
    //     yield call(remove, { oper_id: obj.id });
    //     yield put({
    //       type: 'reduce',
    //       payload: obj.id,
    //     });
    //   }
    // },
    // *add({ payload: params }, { call, put }) {
    //   const response = yield call(add, params);
    //   yield put({
    //     type: 'extend',
    //     payload: response,
    //   });
    // },
  },

  reducers: {
    //   操作reducer
    save(state, action) {
      console.log('请求成功')
 
      return {
        ...state,
        
        orderlists: action.payload,
      };
    },
    // extend(state, { payload: obj }) {
    //   const { operations } = state;
    //   return {
    //     ...state,
    //     operations: [obj, ...operations],
    //   };
    // },
    // reduce(state, { payload: obj_id }) {
    //   const { operations } = state;
    //   return {
    //     ...state,
    //     operations: operations.filter(obj => obj.id !== obj_id),
    //   };
    // },
  },
  subscriptions: {
    setup({ history, dispatch }) {
      dispatch({ type: 'fetch' });
    },
  },
};
